From c3a6ff5ffd42618f509ad3cf6bd637d506dc2811 Mon Sep 17 00:00:00 2001 From: robertl Date: Tue, 29 Aug 2006 16:09:23 +0000 Subject: [PATCH] Don't crash on null filename. Don't rewrite 'comX' (without colon) or else Win 98 breaks. (Sigh.) --- gbser_win.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gbser_win.c b/gbser_win.c index 26b897e84..5b984ed82 100644 --- a/gbser_win.c +++ b/gbser_win.c @@ -112,6 +112,9 @@ static int set_rx_timeout(gbser_handle *h, DWORD timeout) { * COM ports 1 - 9 are "COM1:" through "COM9:" * The one after that is \\.\\com10 - this function tries to plaster over * that. + * + * Worse still, Win98 and ME fail the open if you rename com1 to be \\.\\com1: + * * It returns a pointer to a staticly allocated buffer and is therefore not * thread safe. The buffer pointed to remains valid only until the next * call to this function. @@ -119,7 +122,9 @@ static int set_rx_timeout(gbser_handle *h, DWORD timeout) { const char *fix_win_serial_name_r(const char *comname, char *obuf, size_t len) { if (!gbser_is_serial(comname) || - ((strlen(comname) == 5) && (comname[4] == ':'))) { + ((strlen(comname) == 5) && (comname[4] == ':')) || + ((strlen(comname) == 4) && (case_ignore_strncmp(comname, "com", 3) == 0)) + ) { strncpy(obuf, comname, len); } else { size_t l; @@ -181,7 +186,7 @@ failed: void gbser_deinit(void *handle) { gbser_handle *h = gbser__get_handle(handle); - CloseHandle(h->comport); + CloseHandle(h->comport); xfree(h); } @@ -353,6 +358,10 @@ int gbser_is_serial(const char *port_name) { size_t com_l = strlen(com); unsigned digits; + if (NULL == port_name) { + return 0; + } + /* Skip any prefix */ if (memcmp(port_name, pfx, pfx_l) == 0) { port_name += pfx_l; -- 2.30.2